# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-07-11
# @File : 8_ttshihuo.py

import base64
import requests
import json

res = requests.post(
    url='https://m.captcha.qq.com/',
    data='{"Action":"CheckCaptchaAppId_v1.0.1","CaptchaAppId":2075530305}',
)
esid = res.json()['Response']['SId']

res = requests.post(
    url='https://m.captcha.qq.com/',
    data='{"Action":"GetImageData_v1.0.1","ESId":"%s"}' % esid,
)
data_dict = res.json()


def base64_api(img, typeid):
    data = {"username": "", "password": "", "typeid": typeid, "image": img}
    result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
    if result['success']:
        return True, result["data"]["result"]
    else:
        return False, result["message"]


# 背景图片，base64
l_image = data_dict['Response']['ImageDataL']
status, distance = base64_api(img=l_image, typeid=33)
if not status:
    print("识别错误：", distance)
    exit()
distance = int(distance) - 25
print(distance)
